#pragma once
#include"HashTable.h"

namespace syz
{
	template<class K, class V, class Hash = HashFunc<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
		typedef hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT, Hash> HT;
	public:
		typedef typename HT::iterator iterator;

		unordered_map() : _ht()
		{}

		iterator begin() { return _ht.begin(); }
		iterator end() { return _ht.end(); }
		
		// capacity
		size_t size()const { return _ht.size(); }
		bool empty()const { return _ht.empty(); }

		// Acess
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _ht.Insert(pair<K, V>(key, V()));
			return ret.fisrt->second;
		}

		// lookup
		iterator find(const K& key) { return _ht.Find(key); }
		
		// modify
		pair<iterator, bool> insert(const pair<K, V>& val)
		{
			return _ht.Insert(val);
		}

		iterator erase(iterator it)
		{
			MapKeyOfT kot;
			return _ht.Erase(kot(*it));
		}


	private:
		HT _ht;
	};
}
